package com.webside.points.wechat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	
	private static DateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 

	/*\
	 * Date格式化为String
	 */
	public static String dateFormat(Date date){
		
		return time.format(date);
	}
	/*\
	 * Date格式化为String
	 */
	public static String timeFormat(Date date){
		DateFormat time=new SimpleDateFormat("yyyy-MM-dd"); 
		return time.format(date);
	}
	
	/*
	 * String格式化为Date
	 */
	public static Date dateFormat(String date){
		try {
			return time.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	/*
	 * 字符串格式化为Date
	 */
	public static String strDateFormat(String str){
		StringBuffer buffer=new StringBuffer();
		if(str.length()>=14){
			
			buffer.append(str.substring(0, 4));
			buffer.append("-"+str.substring(4, 6));
			buffer.append("-"+str.substring(6, 8));
			buffer.append(" "+str.substring(8, 10));
			buffer.append(":"+str.substring(10, 12));
			buffer.append(":"+str.substring(12, 14));
		}
		
        return buffer.toString(); 
	}
	
}
